package cn.usian.controller;

import cn.usian.client.UserClient;
import cn.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;

    @RequestMapping("/find")
    public User find(Integer id){

        String url="http://userservice/user/findById?id="+id;
        return restTemplate.getForObject(url,User.class);
    }

    @GetMapping("/findId/{id}")
    public User findId(@PathVariable Integer id){
        return userClient.findId(id);
    }


    @PostMapping("save")
    public boolean save(@RequestBody User user){
        return userClient.save(user);
    }

    @GetMapping("/findByNameId/{id}/{username}")
    public User findByNameId(@PathVariable Integer id,@PathVariable String username){
        return userClient.findByNameId(id,username);
    }
}
